package com.admin.utils.base;



import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;











/**
 * springboot全巨额统一异常处理
 * 
 * @author monxz
 *
 */
@ControllerAdvice
public class BaseControllerException {

	/**
	 * 全局异常捕捉处理
	 * 
	 * @param ex
	 * @return
	 */
	@ResponseBody
	@ExceptionHandler(value = Exception.class)
	public DataResult errorHandler(Exception ex) {
		ex.printStackTrace();
		if(ex instanceof AccessDeniedException) {
			return DataResult.buildFail(DataResultCode.accessDeniedException_code,ex.getMessage());
		}
		
		return DataResult.buildFail(ex.getMessage());

	}
}
